package com.soft.javase.day06.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/24
 */
public class ExtractContact {
    public static void main(String[] args) {
        String regex = "(1[3-9]\\d{9})|(0510-\\d{7})|(0510\\d{7})|(800-\\d{3}-\\d{4})|(800\\d{3}\\d{4})|(\\w+@\\w+\\.[a-zA-Z]{2,3})";
        String text = "你好，若有问题请及时电话联系0510-1231231或者05101112223，也可以发送邮件至123@qq.com。" +
                "若遇紧急问题，可拨打13911112222，或者18523234646。欢迎致电800-820-8820，8008208820。";

        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);

        while (matcher.find()) {
            for (int i = 1; i <= matcher.groupCount(); i++) {
                if (matcher.group(i) != null) {
                    System.out.println("group(" + i + "): " + matcher.group(i));
                }
            }
        }
    }
}
